package services;

import domain.entities.InvestigadorProtocoloCentro;
import domain.entities.LaboratorioCentral;

import java.util.List;
import java.util.regex.Pattern;

public class CriteriaCentralLaboratory extends Criteria{

    private LaboratorioCentral laboratorioCentral;

    public CriteriaCentralLaboratory(LaboratorioCentral laboratorioCentral){
         this.laboratorioCentral = laboratorioCentral;
    }

    @Override
    public boolean isIn(Object element){
        boolean isIn = true;
        LaboratorioCentral other = (LaboratorioCentral)element;

        isIn &= (laboratorioCentral.getName() == null
                ||
                laboratorioCentral.getName().trim().equals("")
                ||
                Pattern.compile(Pattern.quote(laboratorioCentral.getName()), Pattern.CASE_INSENSITIVE).matcher(other.getName()).find()
        ) ;

        isIn &= (laboratorioCentral.getAddress().getAddress() == null
                ||
                laboratorioCentral.getAddress().getAddress().trim().equals("")
                ||
                Pattern.compile(Pattern.quote(laboratorioCentral.getAddress().getAddress()), Pattern.CASE_INSENSITIVE).matcher(other.getAddress().getAddress()).find()
        ) ;

        isIn &= (laboratorioCentral.getAddress().getCity() == null
                ||
                laboratorioCentral.getAddress().getCity().trim().equals("")
                ||
                Pattern.compile(Pattern.quote(laboratorioCentral.getAddress().getCity()), Pattern.CASE_INSENSITIVE).matcher(other.getAddress().getCity()).find()
        ) ;

        isIn &= (laboratorioCentral.getAddress().getProvince() == null
                ||
                laboratorioCentral.getAddress().getProvince().trim().equals("")
                ||
                Pattern.compile(Pattern.quote(laboratorioCentral.getAddress().getProvince()), Pattern.CASE_INSENSITIVE).matcher(other.getAddress().getProvince()).find()
        ) ;

        isIn &= (laboratorioCentral.getAddress().getCountry() == null
                ||
                laboratorioCentral.getAddress().getCountry().trim().equals("")
                ||
                Pattern.compile(Pattern.quote(laboratorioCentral.getAddress().getCountry()), Pattern.CASE_INSENSITIVE).matcher(other.getAddress().getCountry()).find()
        ) ;


        return isIn;
    }
}
